package com.mysite.angular.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mysite.angular.mapper.AcMenuMapper;
import com.mysite.angular.po.AcMenu;
import com.mysite.angular.vo.AcMenuVo;

@Service
public class MenuService {

	@Autowired
	private AcMenuMapper acMenuMapper;

	public List<AcMenu> getMenuList(HashMap<String, Object> searchMap) {
		return acMenuMapper.getListByWhere(searchMap);
	}

	public List<AcMenuVo> getOperatorMenus(Integer operatorId) {
		List<AcMenuVo> menuList = acMenuMapper.getOperatorMenus(operatorId);
		Set<String> parentMenuSet = new HashSet<String>();
		for (AcMenuVo menu : menuList) {
			String[] seqArray = menu.getMenuSeq().split("-");
			for (int i = 0; i < seqArray.length - 1; i++) {
				parentMenuSet.add(seqArray[i]);
			}
		}

		if (!parentMenuSet.isEmpty()) {
			menuList.addAll(acMenuMapper.getOperatorParentMenus(new ArrayList<>(parentMenuSet)));
		}

		return menuList;
	}
}
